package com.usian.admin.controller;

import com.usian.admin.service.AdChannelService;
import com.usian.admin.service.impl.AdChannelServiceImpl;
import com.usian.api.admin.ChannelControllerApi;
import com.usian.model.admin.dtos.ChannelDto;
import com.usian.model.admin.pojos.AdChannel;
import com.usian.model.common.dtos.ResponseResult;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/vi/channel")
public class AdChannelController implements ChannelControllerApi {
    @Autowired
    private AdChannelServiceImpl adChannelService;

    @Override
    @PostMapping("/list")
    @ApiOperation(value = "查询频道信息", notes = "根据名称分页查询")
    @ApiImplicitParam(name = "dto", type = "ChannelDto", value = "查询名称", required = true)
    public ResponseResult findByNameAndPage(@RequestBody ChannelDto dto) {
        return adChannelService.findByNameAndPage(dto);
    }

    @PostMapping("/save")
    @Override
    public ResponseResult save(@RequestBody AdChannel adChannel) {
        return adChannelService.saveAdChannel(adChannel);
    }

    @PostMapping("/update")
    @Override
    public ResponseResult update(@RequestBody AdChannel adChannel) {
        return adChannelService.updateAdChannel(adChannel);
    }

    @DeleteMapping("/del/{id}")
    @Override
    @ApiOperation(value = "删除频道信息", notes = "根据名称分页查询")
    @ApiParam(name = "id", type = "Integer", value = "delete", required = true)
    public ResponseResult del(@PathVariable("id") Integer id) {
        return adChannelService.del(id);
    }


    @GetMapping("/channels")
    @Override
    public ResponseResult findAll() {
        List<AdChannel> list = adChannelService.list();
        return ResponseResult.okResult(list);
    }
}
